﻿/*创建人：盛金龙
 * 用途：项目基本信息
 * 时间：2012-02-08 周三
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Maticsoft.DBUtility;
using System.Data;
using EnvironmentManagerSystem.MODE;
using MySql.Data.MySqlClient;
using System.Web;

namespace EnvironmentManagerSystem.BLL
{
    public class HuanJing
    {
        #region 查询

        /// <summary>
        /// 获取项目单位项目考评信息
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static DevelopprojectbasicinfoDataCollection GetXiangMuKaoPingInfo(string where)
        {
            DevelopprojectbasicinfoDataCollection hs = new DevelopprojectbasicinfoDataCollection();
            try
            {
                StringBuilder br = new StringBuilder();
                br.Append(" SELECT ");
                br.Append(" xiangmukaopingchuliren,xiangmukaopingchuliriqi,chugaokaoping,zhonggaokaoping,huanpingdanweikaoping");
                br.Append(" FROM tbs001_developprojectbasicinfo ");
                br.AppendFormat(" where ProjectName like '{0}' ", where);
                //DataTable dt = DbHelperMySQL.Query(br.ToString()).Tables[0];
                MySqlDataReader dr = DbHelperMySQL.ExecuteReader(br.ToString());
                while (dr.Read())
                {
                    DevelopprojectbasicinfoData model = new DevelopprojectbasicinfoData();
                    if (dr[0] != DBNull.Value)
                        model.xiangmukaopingchuliren = dr[0].ToString();
                    if (dr[1] != DBNull.Value)
                        model.xiangmukaopingchuliriqi = dr[1].ToString();
                    if (dr[2] != DBNull.Value)
                        model.chugaokaoping = dr[2].ToString();
                    if (dr[3] != DBNull.Value)
                        model.zhonggaokaoping = dr[3].ToString();
                    if (dr[4] != DBNull.Value)
                        model.huanpingdanweikaoping = dr[4].ToString();
                    hs.Add(model);
                }
                return hs;
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// 获取项目单位专家会议信息
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static DevelopprojectbasicinfoDataCollection GetZhuanJiaHuiYiInfo(string where)
        {
            DevelopprojectbasicinfoDataCollection hs = new DevelopprojectbasicinfoDataCollection();
            try
            {
                StringBuilder br = new StringBuilder();
                br.Append(" SELECT ");
                br.Append(" huiyishijian,zhuanjiahuiyididian,zhuanjiahuiyizhuanjian,huiyiqueren,zhuanjiahuiyiriqiquerenren,zhuanjiahuiyiriqiquerenriqi,zhuanjiahuiyichuliren,zhuanjiahuiyichuliriqi,zhuanjiahuiyiquerenren,zhuanjiahuiyiquerenriqi ");
                br.Append(" FROM tbs001_developprojectbasicinfo ");
                br.AppendFormat(" where ProjectName like '{0}' ", where);
                //DataTable dt = DbHelperMySQL.Query(br.ToString()).Tables[0];
                MySqlDataReader dr = DbHelperMySQL.ExecuteReader(br.ToString());
                while (dr.Read())
                {
                    DevelopprojectbasicinfoData model = new DevelopprojectbasicinfoData();
                    if (dr[0] != DBNull.Value)
                        model.huiyishijian = dr[0].ToString();
                    if (dr[1] != DBNull.Value)
                        model.zhuanjiahuiyididian = dr[1].ToString();
                    if (dr[2] != DBNull.Value)
                        model.zhuanjiahuiyizhuanjian = dr[2].ToString();
                    if (dr[3] != DBNull.Value)
                        model.huiyiqueren = Convert.ToInt32(dr[3]);
                    if (dr[4] != DBNull.Value)
                        model.zhuanjiahuiyiriqiquerenren = dr[4].ToString();
                    if (dr[5] != DBNull.Value)
                        model.zhuanjiahuiyiriqiquerenriqi = dr[5].ToString();
                    if (dr[6] != DBNull.Value)
                        model.zhuanjiahuiyichuliren = dr[6].ToString();
                    if (dr[7] != DBNull.Value)
                        model.zhuanjiahuiyichuliriqi = dr[7].ToString();
                    if (dr[8] != DBNull.Value)
                        model.zhuanjiahuiyiquerenren = dr[8].ToString();
                    if (dr[9] != DBNull.Value)
                        model.zhuanjiahuiyiquerenriqi = dr[9].ToString();
                    hs.Add(model);
                }
                return hs;
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// 获取项目单位信息
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static Hashtable GetConstructionunit(string where)
        {
            Hashtable hs = new Hashtable();
            try
            {
                StringBuilder br = new StringBuilder();
                br.Append(" SELECT ");
                br.Append(" * ");
                br.Append(" FROM tbs001_developprojectbasicinfo ");
                br.AppendFormat(" where ProjectName like '{0}' ", where);
                DataTable dt = DbHelperMySQL.Query(br.ToString()).Tables[0];
                foreach (DataRow r in dt.Rows)
                {
                    foreach (DataColumn c in dt.Columns)
                    {
                        hs.Add("tbs001_developprojectbasicinfo_" + c.ColumnName, r[c.ColumnName].ToString().Trim());
                    }
                }
                return hs;
            }
            catch
            {
                return null;
            }
        }
        /// <summary>
        /// 受理数据编辑
        /// </summary>
        /// <param name="CName"></param>
        /// <param name="CValue"></param>
        public static int EditTable(string CName)
        {
            int i = 0;
            try
            {
                i = DbHelperMySQL.ExecuteSql(CName);
            }
            catch (Exception ex)
            {

            }
            return i;
        }

        /// <summary>
        /// 受理数据编辑
        /// </summary>
        /// <param name="CName"></param>
        /// <param name="CValue"></param>
        public static string GetCount(string CName)
        {
            MySqlDataReader i = null;
            string re = "";
            try
            {
                i = DbHelperMySQL.ExecuteReader(CName);
                if (i.Read())
                {
                    re = i[0].ToString();
                }
            }
            catch (Exception ex)
            {

            }
            return re;
        }

        /// <summary>
        /// 获取项目单位受理信息
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static DevelopprojectbasicinfoDataCollection GetShouLiInfo(string where)
        {
            DevelopprojectbasicinfoDataCollection hs = new DevelopprojectbasicinfoDataCollection();
            try
            {
                StringBuilder br = new StringBuilder();
                br.Append(" SELECT ");
                br.Append(" nanduxishu,hangyexishu,biaozhunhetongjine,hedinghetongjine,hesuanren,xiangmushouliyushenren,xiangmushouliyushenshijian,xiangmushouliren,xiangmushoulishijian,hedingpinggujine,hetong,shoulituihuishanchu,ProjectMemo,ProjectLog ");
                br.Append(" FROM tbs001_developprojectbasicinfo ");
                br.AppendFormat(" where ProjectName like '{0}' ", where);
                //DataTable dt = DbHelperMySQL.Query(br.ToString()).Tables[0];
                MySqlDataReader dr = DbHelperMySQL.ExecuteReader(br.ToString());
                while (dr.Read())
                {
                    DevelopprojectbasicinfoData model = new DevelopprojectbasicinfoData();
                    if (dr[0] != DBNull.Value)
                        model.nanduxishu = dr[0].ToString();
                    if (dr[1] != DBNull.Value)
                        model.hangyexishu = dr[1].ToString();
                    if (dr[2] != DBNull.Value)
                        model.biaozhunhetongjine = dr[2].ToString();
                    if (dr[3] != DBNull.Value)
                        model.hedinghetongjine = dr[3].ToString();
                    if (dr[4] != DBNull.Value)
                        model.hesuanren = dr[4].ToString();
                    if (dr[5] != DBNull.Value)
                        model.xiangmushouliyushenren = dr[5].ToString();
                    if (dr[6] != DBNull.Value)
                        model.xiangmushouliyushenshijian = dr[6].ToString();
                    if (dr[7] != DBNull.Value)
                        model.xiangmushouliren = dr[7].ToString();
                    if (dr[8] != DBNull.Value)
                        model.xiangmushoulishijian = dr[8].ToString();
                    if (dr[9] != DBNull.Value)
                        model.hedingpinggujine = dr[9].ToString();
                    if (dr[10] != DBNull.Value)
                        model.hetong = dr[10].ToString();
                    if (dr[11] != DBNull.Value)
                        model.shoulituihuishanchu = Convert.ToInt32(dr[11]);
                    model.ProjectMemo = dr["ProjectMemo"].ToString();
                    model.ProjectLog = dr["ProjectLog"].ToString();
                    hs.Add(model);
                }
                return hs;
            }
            catch
            {
                return null;
            }
        }
        /// <summary>
        /// 建设单位信息
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static Hashtable GetConstructionunitTwo(string where)
        {
            Hashtable hs = new Hashtable();
            try
            {
                StringBuilder br = new StringBuilder();
                br.AppendFormat(" SELECT * FROM tbs001_constructionunit where id = {0} ", where);
                DataTable dt = DbHelperMySQL.Query(br.ToString()).Tables[0];
                foreach (DataRow r in dt.Rows)
                {
                    foreach (DataColumn c in dt.Columns)
                    {
                        hs.Add("tbs001_constructionunit_" + c.ColumnName, r[c.ColumnName].ToString().Trim());
                    }
                }
                return hs;
            }
            catch
            {
                return null;
            }
        }
        /// <summary>
        /// 环平单位信息
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static Hashtable GetConstructionunitThree(string where)
        {
            Hashtable hs = new Hashtable();
            try
            {
                StringBuilder br = new StringBuilder();
                br.AppendFormat(" SELECT ");
                br.AppendFormat(" * ");
                br.AppendFormat(" from ");
                br.AppendFormat(" tbs001_evaluationunit where id = {0}", where);
                DataTable dt = DbHelperMySQL.Query(br.ToString()).Tables[0];
                foreach (DataRow r in dt.Rows)
                {
                    foreach (DataColumn c in dt.Columns)
                    {
                        hs.Add("tbs001_evaluationunit_" + c.ColumnName, r[c.ColumnName].ToString().Trim());
                    }
                }
                return hs;
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// 环平单位信息
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static EvaluationUnitData GetConstructionunitThree(string id, string name)
        {
            try
            {
                StringBuilder br = new StringBuilder();
                br.AppendFormat(" SELECT  ");
                br.AppendFormat(" id,UnitName, Address, CertificateNo, Phone, ZipCode, EvaluationScope  ");
                br.AppendFormat(" from ");
                br.AppendFormat(" tbs001_evaluationunit where id = {0}", id);
                DataTable dt = DbHelperMySQL.Query(br.ToString()).Tables[0];
                EvaluationUnitData uni = new EvaluationUnitData();
                #region
                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    uni.UnitName = dr["UnitName"].ToString();
                    uni.Address = dr["Address"].ToString();
                    uni.CertificateNo = dr["CertificateNo"].ToString();
                    uni.Phone = dr["Phone"].ToString();
                    uni.ZipCode = dr["ZipCode"].ToString();
                    uni.EvaluationScope = dr["EvaluationScope"].ToString();
                    #region
                    StringBuilder brb = new StringBuilder();
                    brb.Append(" update tbs001_developprojectbasicinfo set ");
                    brb.AppendFormat(" hp = {0} ", dt.Rows[0]["id"].ToString());
                    brb.AppendFormat(" where ProjectName = '{0}' ", name);
                    DbHelperMySQL.ExecuteSql(brb.ToString());
                    #endregion
                    return uni;
                }

                #endregion
            }
            catch
            {
            }
            return null;
        }

        /// <summary>
        /// 建设项目环境保护审批登记表
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static Hashtable GetHuanJing(string where)
        {
            Hashtable hs = new Hashtable();
            try
            {
                StringBuilder brb = new StringBuilder();
                brb.Append(" SELECT ");
                brb.Append(" * ");
                brb.Append(" FROM ");
                brb.Append(" tbs001_huanjing ");
                brb.AppendFormat(" where 1=1 and name = '{0}' ", where);
                DataTable dtd = DbHelperMySQL.Query(brb.ToString()).Tables[0];
                foreach (DataRow r in dtd.Rows)
                {
                    foreach (DataColumn c in dtd.Columns)
                    {
                        hs.Add(c.ColumnName, r[c.ColumnName].ToString().Trim());
                    }
                }
                return hs;
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// 主要生态破坏控制指标
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static Hashtable GetShengTai(string where)
        {
            Hashtable hs = new Hashtable();
            try
            {
                StringBuilder brb = new StringBuilder();
                brb.Append(" SELECT ");
                brb.Append(" * ");
                brb.Append(" FROM ");
                brb.Append(" tbx001_shengtai ");
                brb.AppendFormat(" where 1=1 and name = '{0}' ", where);
                DataTable dtd = DbHelperMySQL.Query(brb.ToString()).Tables[0];
                foreach (DataRow r in dtd.Rows)
                {
                    foreach (DataColumn c in dtd.Columns)
                    {
                        hs.Add(c.ColumnName, r[c.ColumnName].ToString().Trim());
                    }
                }
                return hs;
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region 编辑



        #endregion

        /// <summary>
        /// 环境数据编辑
        /// </summary>
        /// <param name="CName"></param>
        /// <param name="CValue"></param>
        public static void EditTable(string CName, string CValue, string PName)
        {
            try
            {
                StringBuilder brb = new StringBuilder();
                brb.Append(" UPDATE tbs001_huanjing ");
                brb.Append(" SET ");
                brb.AppendFormat(" {0}='{1}' ", CName, CValue);
                brb.AppendFormat(" where name = '{0}' ", PName);
                DbHelperMySQL.ExecuteSql(brb.ToString());
            }
            catch { }
        }

        /// <summary>
        /// 编辑生态
        /// </summary>
        public static void EditTableShengTai(string CName, string CValue, string PName)
        {
            try
            {
                StringBuilder brb = new StringBuilder();
                brb.Append(" UPDATE tbx001_shengtai ");
                brb.Append(" SET ");
                brb.AppendFormat(" {0}='{1}' ", CName, CValue);
                brb.AppendFormat(" where name = '{0}' ", PName);
                DbHelperMySQL.ExecuteSql(brb.ToString());
            }
            catch { }
        }

        /// <summary>
        /// 获取项目列表
        /// </summary>
        /// <returns></returns>
        public static DataTable GetTable(string where)
        {
            try
            {
                StringBuilder brb = new StringBuilder();
                brb.AppendFormat(" select ProjectName as name,projectreportstate,noticestate,ID as id from tbs001_developprojectbasicinfo where noticestate!=2 {0}", where);
                return DbHelperMySQL.Query(brb.ToString()).Tables[0];
            }
            catch { return null; }
        }

        /// <summary>
        /// 项目基本信息
        /// </summary>
        /// <param name="CName"></param>
        /// <param name="CValue"></param>
        /// <param name="PName"></param>
        public static bool EditTableXM(string CName, string CValue, string log, string str)
        {
            try
            {
                StringBuilder brb = new StringBuilder();
                if (log.Equals("true"))
                {
                    if (DbHelperMySQL.Query(string.Format(" select * from  tbs001_developprojectbasicinfo where ProjectName = '{0}'", CValue)).Tables[0].Rows.Count > 0 ? false : true)
                    {
                        DbHelperMySQL.ExecuteSql(string.Format(" insert into tbs001_developprojectbasicinfo(ProjectName) values('{0}') ", CValue));
                        DbHelperMySQL.ExecuteSql(string.Format(" update tbs001_developprojectbasicinfo set js = {0} where ProjectName = '{1}';", HttpContext.Current.Session["userid"].ToString(), str));
                        DbHelperMySQL.ExecuteSql(string.Format(" insert into tbs001_huanjing(name) values('{0}') ", CValue));
                        DbHelperMySQL.ExecuteSql(string.Format(" insert into tbx001_shengtai(name) values('{0}') ", CValue));
                        return true;
                    }
                    else return false;
                }
                brb.Append(" UPDATE tbs001_developprojectbasicinfo ");
                brb.Append(" SET ");
                brb.AppendFormat(" {0}='{1}' ", CName, CValue);
                brb.AppendFormat(" where ProjectName = '{0}' ", str);
                DbHelperMySQL.ExecuteSql(brb.ToString());
                return true;
            }
            catch { return true; }
        }
    }
}
